package com.mingda.weathermagiccenter.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mingda.weathermagiccenter.mapper.Grib1kmRtMapper;
import com.mingda.weathermagiccenter.pojo.Grib1kmRt;
import com.mingda.weathermagiccenter.service.Grib1kmRtService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
* @author Administrator
* @description 针对表【grib1km_rt】的数据库操作Service实现
* @createDate 2024-09-30 08:40:11
*/
@Service
public class Grib1kmRtServiceImpl extends ServiceImpl<Grib1kmRtMapper, Grib1kmRt>
    implements Grib1kmRtService {


    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @Autowired
    private Grib1kmRtMapper grib1kmRtMapper;

    @Transactional
    public void batchInsertData(List<Grib1kmRt> dataList) {
        // 分批插入数据
        int batchSize = 1000;  // 每批插入的数量

        List<Future<?>> futures = new ArrayList<>();

        for (int i = 0; i < 50000 ; i += batchSize) {
            List<Grib1kmRt> subList = dataList.subList(i, Math.min(i + batchSize, dataList.size()));
            futures.add(taskExecutor.submit(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    //grib1kmRtMapper.insertBatchSomeColumn(subList);
                    //baseMapper.insertOrUpdate(subList);
                    //saveOrUpdateBatch(subList);
                    //saveBatch(subList);
                    return null;
                }
            }));
        }

        for (Future<?> future : futures) {
            try {
                future.get();
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }


}




